//
//  ViewController.swift
//  BBAnimatedTransitioning
//
//  Created by zys on 04/29/2022.
//  Copyright (c) 2022 zys. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    let table = UITableView(frame: .zero, style: .insetGrouped)
    
    var transitionType = [
        "Present",
        "Push"
    ]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "TransitionAnimation"
        view.backgroundColor = .red
        table.delegate = self
        table.dataSource = self
        table.frame = view.bounds
        view.addSubview(table)
    }
}

extension ViewController: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return transitionType.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell:UITableViewCell? = tableView.dequeueReusableCell(withIdentifier: "CELL")
        if cell == nil {
            cell = UITableViewCell(style: .default, reuseIdentifier: "CELL")
        }
        var config = cell?.defaultContentConfiguration()
        config?.text = transitionType[indexPath.row]
        cell?.contentConfiguration = config
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        if "Present" == transitionType[indexPath.row] {
            let vc = PresentAnimatiedController()
            self.present(vc, animated: true)
        } else if "Push" == transitionType[indexPath.row] {
            let vc = PushViewController()
            self.navigationController?.delegate = vc.animator
            self.navigationController?.pushViewController(vc, animated: true)
        }
    }
}

